<?php

namespace App\Admin\Controllers;

use App\Models\Message;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Grid\Filter;
use Encore\Admin\Show;

class MessageController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '留言管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Message());

        $grid->column('id', __('Id'));
        $grid->column('product_id', __('模特产品ID'));
        $grid->column('name', __('用户称呼'));
        $grid->column('email', __('用户邮箱'));
        $grid->column('phone', __('用户电话'));
        $grid->column('info', __('留言信息'));
        $grid->column('created_at', __('创建时间'));

        $grid->actions(function ($actions) {

            // 去掉删除
            $actions->disableDelete();

            // 去掉编辑
            $actions->disableEdit();
        });

        $grid->filter(function(Filter $filter) {
            $filter->equal('product_id', '模特产品ID');
            $filter->like('name', '用户称呼');
            $filter->like('phone', '用户电话');
        });
        $grid->disableExport();
        $grid->disableRowSelector();

        $grid->model()->orderByDesc('id');

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Message::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('product_id', __('Product id'));
        $show->field('name', __('Name'));
        $show->field('email', __('Email'));
        $show->field('phone', __('Phone'));
        $show->field('info', __('Info'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }
}
